package com.turing.post.cardmanagement.impl;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.turing.post.cardmanagement.util.CardATS;
import com.turing.post.cardmanagement.util.CardATSDao;
import com.turing.post.util.GeneralDao;
import com.turing.post.util.PCPSApplicationException;

@Stateless(mappedName = "cardmanagement.impl.CardATSDaoImpl")
@Remote
@Local
public class CardATSDaoImpl implements CardATSDao {

	/**
	 * 实体管理器
	 * 
	 * @see javax.persistence.EntityManager
	 */
	@PersistenceContext
	protected EntityManager _em;
	
	@Override
	public void delete(CardATS cats) throws PCPSApplicationException {
		GeneralDao.remove(_em, cats);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CardATS> getCardATSByAts(String ats) {
		String sql = "select * from CardATS where ats='"+ats+"'";
		Query query = _em.createNativeQuery(sql, CardATS.class);
		return query.getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CardATS> getCardATSByCardNo(String cardNo) {
		String sql = "select * from CardATS where cardNo='"+cardNo+"'";
		Query query = _em.createNativeQuery(sql, CardATS.class);
		return query.getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CardATS> getCardATSByCardSeqNo(String cardSeqNo) {
		String sql = "select * from CardATS where cardSeqNo='"+cardSeqNo+"'";
		Query query = _em.createNativeQuery(sql, CardATS.class);
		return query.getResultList();
	}

	@Override
	public void insert(CardATS cats) throws PCPSApplicationException {
		GeneralDao.insert(_em, cats);
	}

	@Override
	public void update(CardATS cats) throws PCPSApplicationException {
		GeneralDao.update(_em, cats);
	}
}